package com.zsc.shixun.controller;

import com.zsc.shixun.common.CommonResult;
import com.zsc.shixun.common.ResultUtil;
import com.zsc.shixun.service.function.HomeService;
import com.zsc.shixun.utils.LoginMessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 首页
 * </p>
 *
 * @author ZWYZY
 * @since 2020/6/7
 */
@Controller
@RequestMapping("/home")
public class HomeController {
    private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
    @Autowired
    private LoginMessageUtils loginMessageUtils;
    @Autowired
    private HomeService homeService;

    @RequestMapping("/index")
    public String index(HttpServletRequest request) {
        request.setAttribute("homeVO", homeService.getData(loginMessageUtils.getMessage().getLoginUser().getId()));
        return "admin/home/index";
    }

    /**
     * 获取首页显示信息
     *
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    @Secured(value = "ROLE_home_select")
    public CommonResult getData() {
        return ResultUtil.success(homeService.getData(loginMessageUtils.getMessage().getLoginUser().getId()));
    }
}
